const fs = require("fs");
const puppeteer = require("puppeteer");
let browser, page;
(async () => {
  try {
    browser = await puppeteer.launch({
      ignoreHTTPSErrors: true,
      timeout: 30000,
      args: ["--no-sandbox", "--disable-setuid-sandbox"],
    });

    page = await browser.newPage();
    // await page.setRequestInterception(true);

    // await page.on("request", (request) => {
    //   if (request.url() === "https://video.kuaishou.com/graphql") {
    //     console.log(request.url());
    //     console.log("拦截到了这条url然后就该请求了");
    //     page.on("response", (response) => {
    //       if (response.url() === "https://video.kuaishou.com/graphql") {
    //         //const req = response.request();
    //         let message = response.text();
    //         message.then(function (result1) {
    //           results = result1;
    //           console.log(results);
    //         });
    //       }
    //     });
    //   }
    //   request.continue();
    // });

    // await page.goto("http://m.qiushubang.me/234281/106151404.html");
    await page.goto("http://m.qiushubang.me/234281/mulu.html");
    const node = await page.$$eval("#nr nr1", (el) => {
      console.log(el);
      // fs.appendFile("./note.txt", el.innerText, function (e) {
      //   if (e) return;
      //   //输出当前状态
      //   console.log("已完成：" + arr[idx].title);
      //   //递归调用本函数以获取下一章内容
      //   getPage(arr, idx + 1, len);
      // });
    });
  } catch (e) {
    console.log(e);
  }
})();

// (async () => {
//   await page.close();
//   await browser.close();
// })();
